package com.hunsy.fileupload;

import com.jfinal.config.*;
import com.jfinal.core.JFinal;
import com.jfinal.ext.interceptor.SessionInViewInterceptor;
import com.jfinal.render.ViewType;

/**
 * @author hunsy
 */
public class BqConf extends JFinalConfig {

    //上传文件的最终保存位置
    public static String FILE_DIR = "";

    //数据库配置
    public static String DRIVER_CLASS_NAME = "";
    public static String DATASOURCE_URL = "";
    public static String DATASOURCE_USERNAME = "";
    public static String DATASOURCE_PASSWORD = "";

    /**
     * 常量配置
     *
     * @param me
     */
    @Override
    public void configConstant(Constants me) {
        loadPropertyFile("config.txt");
        me.setDevMode(getPropertyToBoolean("devMode", false));
        me.setBaseViewPath("/WEB-INF/views/");
        me.setViewType(ViewType.FREE_MARKER);

        FILE_DIR = getProperty("file_dir");
        DRIVER_CLASS_NAME = getProperty("datasource-driver-class-name");
        DATASOURCE_URL = getProperty("datasource-url");
        DATASOURCE_USERNAME = getProperty("datasource-username");
        DATASOURCE_PASSWORD = getProperty("datasource-password");

        //最多上传4M
        me.setMaxPostSize(1024 * 1024 * 4);
    }

    /**
     * 路由配置。
     *
     * @param me
     */
    public void configRoute(Routes me) {
        me.add("/fileupload", IndexController.class);
    }

    public void configPlugin(Plugins me) {

    }

    public void configInterceptor(Interceptors me) {
        me.add(new SessionInViewInterceptor());
        me.add(new GlobalInterceptor());
    }

    public void configHandler(Handlers me) {

    }

    @Override
    public void afterJFinalStart() {
    }

    /**
     * 启动项目
     *
     * @param args
     */
    public static void main(String[] args) {
        JFinal.start("src/main/webapp", 89, "/", 5);
    }
}
